package com.example.review;



import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;


import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;

import com.example.review.base.BaseActivity;
//这里采用的是实现View.OnClickListener来编写点击事件
public class chapterThreeActivity extends BaseActivity implements View.OnClickListener {
    //在这里声明，主要是方便下面点击事件里面
    private EditText editText;
    private ImageView imageView;
    private ProgressBar progressBar;
    private ProgressBar progressBar2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chapter_three);
        Button button=findViewById(R.id.bianji);
        button.setOnClickListener(this);
        Button button1=findViewById(R.id.change);
        button1.setOnClickListener(this);
        Button button2=findViewById(R.id.nones);
        button2.setOnClickListener(this);
        Button button3=findViewById(R.id.add);
        button3.setOnClickListener(this);
        Button button4=findViewById(R.id.allog);
        button4.setOnClickListener(this);
        Button button5=findViewById(R.id.plog);
        button5.setOnClickListener(this);
        Button button6 =findViewById(R.id.button1A);
        button6.setOnClickListener(this);
        Button button2a=findViewById(R.id.button2A);
        button2a.setOnClickListener(this);
        editText=findViewById(R.id.editFort);
        imageView=findViewById(R.id.imageView);
        progressBar=findViewById(R.id.progressBar);
        progressBar2=findViewById(R.id.progressBar2);
        //将现有的标题栏隐藏
        ActionBar actionBar=getSupportActionBar();
        if (actionBar != null){
            actionBar.hide();
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bianji:
                String text =editText.getText().toString();
                Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
                break;
            case R.id.change:
                //改变图片框的图片
                imageView.setImageResource(R.drawable.tx);
                break;
            case R.id.nones:
                //完全消失，且不占用屏幕空间
                if (progressBar.getVisibility()==View.VISIBLE){
                    progressBar.setVisibility(View.GONE);
                }else {
                    progressBar.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.add:
                int progress=progressBar2.getProgress();
                progress=progress+100;
                progressBar2.setProgress(progress);
                break;
            case R.id.allog:
                //通过AlertDialog.Builder创建一个AlertDialog的实例 参数为上下文
                AlertDialog.Builder alertDialog= new AlertDialog.Builder(chapterThreeActivity.this);
                //标题
                alertDialog.setTitle("这是一个危险操作");
                //具体内容
                alertDialog.setMessage("你当前的操作，有可能让您的设备中毒，并且设备瘫痪");
                //可否用Back键关闭对话框等
                alertDialog.setCancelable(false);
                alertDialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //为对话框设置 确定按钮的点击事件
                        //todo
                    }
                });
                alertDialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //为对话框设置 取消按钮的点击事件
                        //todo
                    }
                });
                //最后调 用show() 方法将对话框显示出来
                alertDialog.show();
                break;
            case R.id.plog:
                ProgressDialog progressDialog=new ProgressDialog(chapterThreeActivity.this);
                progressDialog.setTitle("网络波动");
                progressDialog.setMessage("正在拼命加载中，请耐心等待");
                progressDialog.setCancelable(true);
                progressDialog.show();
                break;
            case R.id.button1A :
                Intent intent =new Intent(chapterThreeActivity.this,chapterThree2Activity.class);
                startActivity(intent);
            case R.id.button2A :
                Intent intent2a =new Intent(chapterThreeActivity.this,chapterThree3Activity.class);
                startActivity(intent2a);
            default:
                break;
        }
    }
}